Add preview mode to all mutators#7
Merged
Merged
Conversation
Every function that writes to disk takes preview = FALSE. With preview = TRUE it returns a hacer_preview object describing the change and writes nothing. The HACER_PREVIEW=1 env var flips the default for an entire session or one-shot CLI invocation. Mutators covered: roll_day, run_monday, fix_parents, next_day, sync_from_daily, instantiate_todo. Architecture: - R/preview.R holds the new infrastructure: .preview_default() reads the env var, .new_preview() builds the result object, .line_diff() computes an LCS-based per-file diff, and .write_or_preview() is the single dispatch each mutator calls with its computed targets. - R/io.R splits each writer (write_todo_txt, write_markdown, write_simple_html) into a build_*_lines() function plus a thin writeLines wrapper, so mutators can compute new file contents in memory before deciding whether to apply. - print.hacer_preview() renders a short summary: created files, modified files with +/- counts, and done.log appends. run_monday's archive copy and git commit are skipped in preview mode since they're side effects beyond the file system. 32 new tests in test_preview.R cover: zero-mtime guarantee on disk, env-var default flipping, print output, and preview-then- apply equivalence with non-preview runs for roll_day, fix_parents, sync_from_daily, and instantiate_todo. Bump version to 0.1.6.
README: add a "Look before you leap: preview mode" subsection under the LLM CLI agents section with print output, the HACER_PREVIEW=1 one-shot CLI examples, and the list of functions that support it. CLAUDE.md: brief Preview mode section pointing at R/preview.R and the .write_or_preview() dispatch pattern that each mutator follows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Task 4 of
Plan.md: every function that writes to disk takespreview = FALSE. Withpreview = TRUEit returns ahacer_previewobject describing the change and writes nothing. TheHACER_PREVIEW=1env var flips the default for an entire session or one-shot CLI invocation.Mutators covered:
roll_day,run_monday,fix_parents,next_day,sync_from_daily,instantiate_todo.Architecture
R/preview.Rholds the new infrastructure:.preview_default()reads the env var,.new_preview()builds the result object,.line_diff()computes an LCS-based per-file diff, and.write_or_preview()is the single dispatch each mutator calls with its computed targets.R/io.Rsplits each writer (write_todo_txt,write_markdown,write_simple_html) into abuild_*_lines()function plus a thinwriteLineswrapper, so mutators can compute new file contents in memory before deciding whether to apply.print.hacer_preview()renders a short summary: created files, modified files with +/- counts, anddone.logappends.run_monday's archive copy and git commit are skipped in preview mode since they're side effects beyond the file system.README and CLAUDE.md document the new mode with a one-shot CLI example. Version bumped to 0.1.6.
Test plan
inst/tinytest/test_preview.R: zero-mtime guarantee on disk, env-var default flipping, print output, and preview-then-apply equivalence with non-preview runs forroll_day,fix_parents,sync_from_daily, andinstantiate_todotinyrox::document(); tinypkgr::install(); tinytest::test_package("hacer")clean